package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

type commodity struct {
	title    string
	price    float64
	quantity int
}

func main() {
	file, err := os.Open("products.txt")
	if err != nil {
		panic(err)
	}
	commodities := make([]commodity, 0)
	reader := bufio.NewReader(file)
	for {
		line, _, err := reader.ReadLine()
		if err == io.EOF {
			break
		}
		split := strings.Split(string(line), ";")
		quantity, _ := strconv.Atoi(split[2])
		price, err := strconv.ParseFloat(split[2], 2)
		commodities = append(commodities, commodity{split[0], price, quantity})
	}

	for _, v := range commodities {
		fmt.Printf("title: %s  price: %f  quantity: %d \n", v.title, v.price, v.quantity)
	}

}
